package com.gr.catanddog_common.utils;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author 大睡大唬
 * @version 1.0
 * @description: TODO
 * @date 2024/3/5 14:35
 */
@Component
@Slf4j
public class ALiYunSample {
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
    public  static SendSmsResponse MsgRouting(String phone,String code) throws Exception {
        com.aliyun.dysmsapi20170525.Client client = ALiYunSample.createClient("LTAI5t6wiQvRkqFo6SMqD3u4","2f5nkYwE8JDhUhIWXav4OKEJJvKQVz");
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setSignName("CatAndDog")
                .setTemplateCode("SMS_465386103")
                .setPhoneNumbers(phone)
                .setTemplateParam(code);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        return client.sendSmsWithOptions(sendSmsRequest, runtime);
    }

}
